home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 811 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: clamage@Eng.Sun.COM (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Referencing pointers after delete
  5. Date: 21 Mar 1996 13:50:12 PST
  6. Organization: Sun Microsystems Inc.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4isibn$el3@engnews1.Eng.Sun.COM>
  9. References: <4is60i$ft6@galaxy.ucr.edu>
  10. Reply-To: clamage@Eng.Sun.COM
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. X-Original-Date: 21 Mar 1996 21:40:07 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMVHPLUy4NqrwXLNJAQFY5AH/TZETmkaO7tgOKmbLxYy6niBGvq9CSJTa
  15.     bMjoH7ZH7ROmptlVHOVzX/fWomt8iZr7oxi8w851xSEN4Wk+EMQ46A==
  16.     =bhe7
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article ft6@galaxy.ucr.edu, thp@cs.ucr.edu (Tom Payne) writes:
  20. >....  It seems that to accomodate
  21. >certain hardware-based validity checkers for pointers, the standard
  22. >has precluded the possibility of portable software-based validity
  23. >checking.  IMHO an unfortunate decision.
  24.  
  25. Even if the value of a pointer after its referent was deleted were 
  26. required to be valid, it is still not possible to write a portable pointer
  27. validity checker for C or C++. Example, assuming that it is always safe
  28. to read the value of any pointer:
  29.  
  30.     void foo(int* p) {
  31.         // is p valid?
  32.     }
  33. How are you going to determine portably whether p is valid in foo? 
  34.  
  35. I might call foo like this, for example:
  36.     int f2() {
  37.         struct two { int a, b; } ray[10];
  38.         foo(&ray[5].b);
  39.     }
  40. The value of p in foo is valid, even though it does not correspond to any
  41. heap object or the start of any entire object. Furthermore, suppose in foo
  42. I save the value of p in a static variable and use it again in another
  43. invocation of foo. Is it still valid? If the current address of p
  44. is the same as the saved value from a previous invocation, does it refer
  45. to the same object?
  46.  
  47. These questions can be answered in system-specific ways, but there is
  48. no portable method. A saved address might or might not still be valid.
  49. Addresses that compare equal might refer to the same or to different
  50. objects. 
  51. ---
  52. Steve Clamage, stephen.clamage@eng.sun.com
  53. ---
  54. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  55.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  56.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  57.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  58.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  59. ]
  60.